package com.lagou.mongodbtest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("resumeDAO")
public class ResumeDAOImpl implements ResumeDAO {
    /**
     * MongoDB操作的模板对象
     */
    @Autowired
    private MongoTemplate mongoTemplate;

    /**
     * 添加简历
     *
     * @param resume 要添加的简历
     */
    @Override
    public void insert(Resume resume) {
        mongoTemplate.insert(resume, "lg_resume_datas");
    }

    /**
     * 根据名字查找简历
     *
     * @param name 名字
     * @return 简历列表
     */
    @Override
    public List<Resume> findByName(String name) {
        Query query = new Query();
        query.addCriteria(Criteria.where("name").is(name));

        return mongoTemplate.find(query, Resume.class, "lg_resume_datas");
    }
}
